package com.guli.cart.vo;

//购物车vo信息

import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;

public class CartVo {

    //所有商品信息
    @Setter @Getter
    private List<CartItemVo> items;

    /**
     * 商品数量
     */
    private Integer countNum;

    /**
     * 商品类型数量
     */
    private Integer countType;

    /**
     * 商品总价
     */
    private BigDecimal totalAmount = BigDecimal.ZERO;

    /**
     * 减免价格
     */
    @Setter @Getter
    private BigDecimal reduce = BigDecimal.ZERO;

    /**
     * 应付价格
     */
    private BigDecimal payAmount;


    public Integer getCountNum() {
        int num = 0;
        for (CartItemVo item : this.items) {
            num += item.getCount();
        }
        return num;
    }

    public Integer getCountType() {
        int num = 0;
        for (CartItemVo item : this.items) {
            num += 1;
        }
        return num;
    }
    //总价
    public BigDecimal getTotalAmount() {
        BigDecimal zero = BigDecimal.ZERO;
        for (CartItemVo item : this.items) {
            if(item.getCheck()){
                zero = zero.add(item.getTotalPrice());
            }
        }
        return zero;
    }
    //应付总价
    public BigDecimal getPayAmount() {
        return getTotalAmount().subtract(this.reduce);
    }


}
